//无效文件

let configpath = process.argv[2] ? process.argv[2] : "./config.js";
let config1 = require(configpath);
var cluster = require('cluster');
if (!config1.list)
    return console.log("配置错误");
let serverList = config1.list;
 
//子进程监听消息处理函数
var workerListener = function (msg) {
    
    console.log(arguments);
	
    if (msg.access)
        console.log('user access %s, worker [%d]', 
                           msg.access, msg.workerid);
};
//fork新的子进程函数
var forkWorker = function(listener){
    var worker = cluster.fork();
    console.log('worker [%d] has been created',    worker.process.pid);
    worker.on('message', listener);
    return worker;
};
 
//Cluster处理
var cluster = require('cluster');
if (cluster.isMaster) {
    for (var i = 0; i < 10; i++) {
      setTimeout(()=>{
                  word=forkWorker(workerListener);
        word.send(">>>>>>>>>>>");
      },500*i)

    }
} else {
    cluster.worker.on('message', function(){
         let udpProxy = require("./udpproxy.js").udpProxy;
let createtcpProxy = require("./tcpproxy.js").createtcpProxy;
    });

    //var app = require('./app');
    //return app.listen(3000);
    setTimeout(()=>{},500);
/*    process.on("message",function(){
        console.log(JSON.stringify(arguments));
    })*/
}
 
//Cluster收到子进程退出消息
cluster.on('exit', function (worker, code, signal) {
    console.log('worker [%d] died %s, fork a new one.',
        worker.process.pid, code || signal);
    forkWorker(workerListener);
});
//Cluster收到子进程运行消息
cluster.on('online', function(worker){
    console.log('worker [%d] is running.', worker.process.pid);
});